﻿using Data;
using Infrastructure.States;
using Logic;
using UI.Support;
using UnityEngine;

namespace UI
{
    public class MenuWindow : BaseWindow
    {
        private GameStateMachine _stateMachine;
        [SerializeField] private ButtonClick _playButton;

        public void Construct(GameStateMachine stateMachine) =>
            _stateMachine = stateMachine;

        protected override void OnAwake()
        {
            _playButton.Clicked += PlayGame;
            base.OnAwake();
        }

        private void PlayGame()
        {
            Unsubscribe();
            _stateMachine.Enter<LoadLevelState, string>(Constants.Main);
        }

        protected override void Close() =>
            Utils.Quit();

        private void Unsubscribe() =>
            _playButton.Clicked -= PlayGame;
    }
}